package org.example.bean.service;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.example.bean.model.LoginTypeEnum;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.stereotype.Component;

@Component
public class LoginCommonStragegyRegistry {

    @Resource
    private BeanFactory beanFactory;

    private Map<LoginTypeEnum, LoginStragegy> loginStragegyMap = new HashMap<>();

    public Map<LoginTypeEnum, LoginStragegy> mapGet() {
        return this.loginStragegyMap;
    }

    /**
     * 初始化策略
     * 
     * @param loginTypeEnum
     * @param userNameLoginService
     */
    public void registry(LoginTypeEnum loginTypeEnum, Class<?> clazz) {
        LoginStragegy loginStragegy = (LoginStragegy) beanFactory.getBean(clazz);// 获取bean实例，这里使用了Spring的BeanFactory来获取，也可以使用其他方式获取。
        loginStragegyMap.put(loginTypeEnum, loginStragegy);// 将实例放入map中。
    }
}
